﻿using System;
using System.Collections.Generic;

using E.BLL;
using E.Model;
using E.Web.UI.Page;

using X.Pager;
using X.Pager.List;
using X.Common;
using E.Enum;

namespace E.Web.Teacher.student
{
    public partial class Score : TeacherBasePage
    {
        public IList<UserListModel> userList;
        public Dictionary<int, string> certificateList;
        public string username;
        public string email;
        public string loginid, fromDate, toDate;
        public int currentCertificateID;
        public int delflag = -1;

        protected override void ShowPage()
        {
            switch (authority)
            {
                case EnumTeacherAuthority.Internals:
                    certificateList = (new TeacherBLL()).GetTeacherProjectInfo(teacherid);
                    break;
                case EnumTeacherAuthority.Normal:
                    certificateList = (new CourseBLL()).GetCertificateList();
                    break;
                case EnumTeacherAuthority.Admin:
                    certificateList = (new CourseBLL()).GetInternalProjectList();
                    break;
                default: break;
            }

            InitSearchDateTime();
            string act = XRequest.GetString("act");
            username = XRequest.GetString("UserNameTxt");
            email = XRequest.GetString("EmailTxt");
            loginid = XRequest.GetString("LoginIDTxt");
            currentCertificateID = XRequest.GetInt("CertificateSlt", -1);
            delflag = XRequest.GetInt("DelFlagSlt", -1);

            if (act == "s")
            {
                UserBLL bll = new UserBLL();
                UserModel model = new UserModel();
                model.UserName = username;
                model.Email = email;
                model.LoginID = loginid;
                model.AreaID = -1;
                model.CurrentCertificateID = currentCertificateID;
                model.DelFlagInt = delflag;
                model.IsPublicInt = 0;
                model.EntryFromDate = fromDate;
                model.EntryToDate = toDate;

                ListModel listModel = new ListModel();

                CheckPageIndexValue(XRequest.GetInt("s", 1) - 1, XRequest.GetInt("g", 0), XRequest.GetInt("z", customerPageSize));
                listModel = bll.GetUserListByCondition(model, customerPageSize, pageIndex);
                if (listModel.TotalCount > 0)
                {
                    count = listModel.TotalCount;
                    userList = listModel.UserList;
                    PagerBase pager = new ListPager(count, pageIndex, currentPgGroup, customerPageSize, defaultPagesInGroup);

                    Dictionary<string, string> parms = new Dictionary<string, string>();
                    parms.Add("act", act);
                    parms.Add("UserNameTxt", username);
                    parms.Add("LoginIDTxt", loginid);
                    parms.Add("EmailTxt", email);
                    parms.Add("CertificateSlt", currentCertificateID.ToString());
                    mypager = pager.DrawPager("selfpager", parms);
                }
            }
        }

        private void InitSearchDateTime()
        {
            try
            {
                if (!XRequest.GetString("FromDateTxt").Equals(""))
                {
                    Convert.ToDateTime(XRequest.GetString("FromDateTxt"));
                    fromDate = XRequest.GetString("FromDateTxt");
                }

                if (!XRequest.GetString("ToDateTxt").Equals(""))
                {
                    Convert.ToDateTime(XRequest.GetString("ToDateTxt"));
                    toDate = XRequest.GetString("ToDateTxt");
                }
            }
            catch (Exception ex)
            {

            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}
